import pytest
from playwright.sync_api import sync_playwright
from config.env import URLDve
from utils.logger import log
from  config.path import video_log_path


@pytest.fixture(scope="function", autouse=True)
def page():
    #初始化
    playwright = sync_playwright().start()
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    context.tracing.start(snapshots=True,sources=True,screenshots=True)
    log.debug("浏览器启动成功")
    page = context.new_page()
    page.goto(URLDve.OJ_backend)

    #返回上下文
    yield page

    #关闭释放服务
    page.wait_for_timeout(3000)
    context.tracing.stop(path = "trace.zip")
    context.close()
    browser.close()
    playwright.stop()
    log.debug("浏览器关闭成功")